unit IssueDocFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, AppUtils, BaseForm, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters, dxSkinsCore, dxSkinOffice2010Blue, dxSkinscxPCPainter,
  cxPropertiesStore, dxLayoutLookAndFeels, dxLayoutContainer, dxLayoutControl,
  dxSkinOffice2013White, cxStyles, cxCustomData, cxFilter, cxData,
  cxDataStorage, cxEdit, cxNavigator, Data.DB, cxDBData, dxLayoutcxEditAdapters,
  dxLayoutControlAdapters, cxContainer, Vcl.Menus, Vcl.StdCtrls, cxButtons,
  cxTextEdit, cxMaskEdit, cxDropDownEdit, cxLookupEdit, cxDBLookupEdit,
  cxDBLookupComboBox, cxGridLevel, cxClasses, cxGridCustomView,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGrid, FIBDataSet,
  pFIBDataSet, cxImageComboBox;

type
  TIssueDocForm = class(TDezForm)
    grp1: TdxLayoutGroup;
    lc1: TdxLayoutControl;
    lf1: TdxLayoutLookAndFeelList;
    lcf1: TdxLayoutCxLookAndFeel;
    prop1: TcxPropertiesStore;
    v1: TcxGridDBTableView;
    l1: TcxGridLevel;
    grd1: TcxGrid;
    itmlc1Item1: TdxLayoutItem;
    grplc1Group1: TdxLayoutGroup;
    grplc1Group2: TdxLayoutGroup;
    cbbKontr: TcxLookupComboBox;
    itmlc1Item11: TdxLayoutItem;
    cbbUser: TcxLookupComboBox;
    itmlc1Item12: TdxLayoutItem;
    cbbArkObject: TcxLookupComboBox;
    itmlc1Item13: TdxLayoutItem;
    btnRefresh: TcxButton;
    itmlc1Item14: TdxLayoutItem;
    dsRep: TpFIBDataSet;
    srcRep: TDataSource;
    clv1ARCPLACE: TcxGridDBColumn;
    clv1STRCODE: TcxGridDBColumn;
    clv1OBJNAME: TcxGridDBColumn;
    clv1ROOMNAME: TcxGridDBColumn;
    clv1RACKNAME: TcxGridDBColumn;
    clv1SHELF: TcxGridDBColumn;
    clv1NUMBER: TcxGridDBColumn;
    clv1FIO: TcxGridDBColumn;
    clv1ORDERDOC: TcxGridDBColumn;
    clv1KONTRAGENT: TcxGridDBColumn;
    clv1KONTRNAME: TcxGridDBColumn;
    clv1STATE: TcxGridDBColumn;
    dsArcObject: TpFIBDataSet;
    srcArcObject: TDataSource;
    btnExcel: TcxButton;
    itmlc1Item15: TdxLayoutItem;
    clv1CNAME: TcxGridDBColumn;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnRefreshClick(Sender: TObject);
    procedure btnExcelClick(Sender: TObject);
  private
    { Private declarations }
    procedure RefreshDS;
    procedure OpenDS;
  public
    { Public declarations }
  end;

var
  IssueDocForm: TIssueDocForm;

implementation

uses cmDBUnit;

{$R *.dfm}


procedure TIssueDocForm.btnExcelClick(Sender: TObject);
var
  s: TStrings;
begin
  s:= TStringList.Create;
  try
    s.Add(Self.Caption);
    s.Add(cbbKontr.EditText);
    ExportInExcel(grd1,s);
  finally
    FreeAndNil(s);
  end;
end;

procedure TIssueDocForm.btnRefreshClick(Sender: TObject);
begin
  RefreshDS;
end;

procedure TIssueDocForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action:= caFree;
end;

procedure TIssueDocForm.FormCreate(Sender: TObject);
begin
  LoadForm(prop1,Self.Name);
  OpenDS;
end;

procedure TIssueDocForm.OpenDS;
begin
  cmDb.ds_KONTRAGENT.Open;
  cmDb.ds_WORKER.Open;
  dsArcObject.Open;
end;

procedure TIssueDocForm.RefreshDS;
begin
  v1.BeginUpdate(lsimImmediate);
  try
    with dsRep do begin
      Close;
      MainWhereClause:= 'A.STATE in (2,3)';
      if cbbKontr.EditValue<>null then
        MainWhereClause:= MainWhereClause+#10#13+' and DG.KONTRAGENT ='+VarToStr(cbbKontr.EditValue);
      if cbbUser.EditValue<>null then
        MainWhereClause:= MainWhereClause+#10#13+' and A.WORKER ='+VarToStr(cbbUser.EditValue);
      if cbbArkObject.EditValue<>null then
        MainWhereClause:= MainWhereClause+#10#13+' and AO.CODE ='+VarToStr(cbbArkObject.EditValue);
      Open;
    end;
  finally
    v1.EndUpdate;
    v1.ViewData.Expand(true);
  end;
end;

initialization
 RegisterClass(TIssueDocForm);
end.
